package com.example.hp.service.impl;

import com.example.hp.entity.Enrollments;
import com.example.hp.dao.EnrollmentsDao;
import com.example.hp.service.EnrollmentsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (Enrollments)表服务实现类
 *
 * @author makejava
 * @since 2024-12-15 16:49:03
 */
@Service("enrollmentsService")
public class EnrollmentsServiceImpl implements EnrollmentsService {
    @Resource
    private EnrollmentsDao enrollmentsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param enrollmentId 主键
     * @return 实例对象
     */
    @Override
    public Enrollments queryById(Integer enrollmentId) {
        return this.enrollmentsDao.queryById(enrollmentId);
    }

    /**
     * 分页查询
     *
     * @param enrollments 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Enrollments> queryByPage(Enrollments enrollments, PageRequest pageRequest) {
        long total = this.enrollmentsDao.count(enrollments);
        return new PageImpl<>(this.enrollmentsDao.queryAllByLimit(enrollments, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param enrollments 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(Enrollments enrollments) {
        int insert = enrollmentsDao.insert(enrollments);
        return insert;
    }

    /**
     * 修改数据
     *
     * @param enrollments 实例对象
     * @return 实例对象
     */
    @Override
    public Enrollments update(Enrollments enrollments) {
        this.enrollmentsDao.update(enrollments);
        return this.queryById(enrollments.getEnrollmentId());
    }

    /**
     * 通过主键删除数据
     *
     * @param enrollmentId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer enrollmentId) {
        return this.enrollmentsDao.deleteById(enrollmentId) > 0;
    }
}
